package queue;

import array.Array;

public class ArrayQueue<E> implements Queue<E>{
    Array<E> array;
    public ArrayQueue(int capacity){
        array = new Array<E>(capacity);
    }
    public ArrayQueue(){
        array = new Array<E>();
    }
    public int getSize() {
        return array.getSize();
    }

    public boolean isEmpty() {
        return array.isEmpty();
    }

    public void enqueue(E e) {
        array.addLast(e);
    }

    public E dequeue() {
        return array.removeFirst();
    }

    public E getFront() {
        return array.getLast();
    }

    public int getCapacity(){
        return array.getCapacity();
    }

    @Override
    public String toString() {
        StringBuilder res = new StringBuilder();
        res.append("Queue:");
        res.append("front[");
        for (int i = 0; i < array.getSize(); i++) {
            res.append(array.get(i));
            if (i != array.getSize() - 1) {
                res.append(",");
            }
        }
        res.append("] tail");
        return res.toString();
    }

    public static void main(String[] args) {
        ArrayQueue<Integer> arrayQueue  = new ArrayQueue<Integer>();
        for(int i = 0 ;i < 10 ;i++){
            arrayQueue.enqueue(i);
            System.out.println(arrayQueue);

            if(i % 3 == 2){
                arrayQueue.dequeue();
                System.out.println(arrayQueue);
            }
        }
    }
}
